//
//  MemberController.m
//  DirectMember
//
//  Created by jzd on 2018/6/25.
//  Copyright © 2018年 宋佳. All rights reserved.
//

#import "MemberController.h"
#import "MemberCell.h"

@interface MemberController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableV;
@property (weak, nonatomic) UISegmentedControl *segment;
@end

@implementation MemberController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitleView];
    
    [self.tableV registerNib:[UINib nibWithNibName:NSStringFromClass([MemberCell class]) bundle:nil] forCellReuseIdentifier:MemberCellIdentifier];
}
-(void)setTitleView{
    // 1.设置titleView
    UISegmentedControl *segMentControl = [[UISegmentedControl alloc] initWithItems:@[@"已激活",@"未激活"]];
    
    
    //    UIImage *select_Image = [[UIImage imageNamed:@"white"] resizableImageWithCapInsets:UIEdgeInsetsMake(2, 0.1, 0.1, 0.1)];
    
    // 2.设置背景图片
    // 普通状态
    //    [segMentControl setBackgroundImage:[UIImage imageNamed:@"remeber_Select"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    
    // 选中状态
    //    [segMentControl setBackgroundImage:[UIImage imageNamed:@"whiteAA"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
    
    // 3.设置字体颜色
    [segMentControl setTitleTextAttributes:@{
                                             NSForegroundColorAttributeName : [UIColor whiteColor]
                                             } forState:UIControlStateNormal];
    [segMentControl setTitleTextAttributes:@{
                                             NSForegroundColorAttributeName : TITLECOLOR
                                             } forState:UIControlStateSelected];
    
    // 4.设置选中的索引
    segMentControl.selectedSegmentIndex = 0;
    
    // 5.设置前景色
    segMentControl.tintColor = [UIColor whiteColor];
    
    [segMentControl addTarget:self action:@selector(segmentValueChange:) forControlEvents:UIControlEventValueChanged];
    
    self.navigationItem.titleView = segMentControl;
    self.segment = segMentControl;
}
-(void)segmentValueChange:(UISegmentedControl *)seg{
    [self.tableV reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.segment.selectedSegmentIndex == 0) {
        return 7;
    }else{
        return 3;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MemberCell *cell = [tableView dequeueReusableCellWithIdentifier:MemberCellIdentifier];
    if (self.segment.selectedSegmentIndex == 0) {
        cell.jihuoBut.hidden = YES;
    }else{
        cell.jihuoBut.hidden = NO;
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}


@end
